home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Pictures / TIFF / Tiff Utilties / Tiff Window DEMO / change color.c < prev    next >
C/C++ Source or Header  |  1993-10-20  |  8KB  |  187 lines

  1. #include "my color.h"
  2. /*
  3.         The routines in this module will change the chosen part of the window 
  4.         or control to whatever color the user wants .
  5.  
  6. */
  7. change_color(window_region, aWindow)    /* this will change a window's color */
  8. CWindowPtr    aWindow;
  9. short    window_region;
  10. {
  11. Point    center = {0, 0};    /* This will tell "GetColor" to center the dialog window */
  12. RGBColor    selected_color;
  13. AuxWinHndl    some_new_colors = 0;/* This is really dumb, but LSC calls AuxWinHandle, AuxWinHndl??? */
  14. Boolean        aux_test;
  15.  
  16.     GetPort(&savedPort);        /* Save the Graf Port */
  17.  
  18. /*        WARNING:  Inside Mac Vol 5 document bug! */
  19. /*             Inside Mac Vol 5 on page 207 defines GetAuxWin as returning a CTabHandle,
  20.             This is wrong, it really returns an AuxWinHandle!!!!  this drove me crazy for
  21.             an hour before I realized that it didn't make since for GetAuxWin to return
  22.             a CTabHandle. It made more sense for it to return an AuxWinHandle. (Note 
  23.             the AuxWin in both words)  Some quick experimenting with the Think C 
  24.             source Code Debugger proved this to  be correct!  
  25.             P.S. If you believe Inside Mac and treat GetAuxWin as returning a CTabHandle
  26.             you will notice that your program will do strange things and then 
  27.             really bomb!
  28. */
  29.  
  30. /* I want to call GetAuxWin to get the window's ColorTable that I created when the window 
  31.     was first defined, then I can change the colors the way the user wants */
  32.     
  33.     aux_test =     GetAuxWin(aWindow, &some_new_colors);    /* get this window's current color definitions */
  34.     if(!aux_test) /* if there are no Auxillary window records then lets scram! */
  35.         return;    
  36.  
  37.     HLock((**some_new_colors).awCTable);    /* Lock it just in case SetWinColor or GetColor de-references the Handle */
  38.     
  39.     switch(window_region)    /* depending on which part of the window they want to change the color */
  40.     {
  41.     
  42.         case CONTENT:
  43.             if(!GetColor(center, "\pContent Region", 
  44.                 &(**(**some_new_colors).awCTable).ctTable[0].rgb, &selected_color))
  45.                     { SysBeep(10); return; }
  46.             (**(**some_new_colors).awCTable).ctTable[0].value = wContentColor;
  47.             (**(**some_new_colors).awCTable).ctTable[0].rgb.red = selected_color.red;
  48.             (**(**some_new_colors).awCTable).ctTable[0].rgb.green = selected_color.green;
  49.             (**(**some_new_colors).awCTable).ctTable[0].rgb.blue = selected_color.blue;
  50.             break;
  51.             
  52.         case FRAME:
  53.             if(!GetColor(center, "\pWindow Frame", 
  54.                     &(**(**some_new_colors).awCTable).ctTable[1].rgb, &selected_color))
  55.                         { SysBeep(10); return; }
  56.             (**(**some_new_colors).awCTable).ctTable[1].value = wFrameColor;
  57.             (**(**some_new_colors).awCTable).ctTable[1].rgb.red = selected_color.red;
  58.             (**(**some_new_colors).awCTable).ctTable[1].rgb.green = selected_color.green;
  59.             (**(**some_new_colors).awCTable).ctTable[1].rgb.blue = selected_color.blue;
  60.             break;
  61.             
  62.         case TEXT:
  63.             if(!GetColor(center, "\pWindow Text", 
  64.                 &(**(**some_new_colors).awCTable).ctTable[2].rgb, &selected_color))
  65.                     { SysBeep(10); return; }
  66.             (**(**some_new_colors).awCTable).ctTable[2].value = wTextColor;
  67.             (**(**some_new_colors).awCTable).ctTable[2].rgb.red = selected_color.red;
  68.             (**(**some_new_colors).awCTable).ctTable[2].rgb.green = selected_color.green;
  69.             (**(**some_new_colors).awCTable).ctTable[2].rgb.blue = selected_color.blue;
  70.             break;
  71.         
  72.         case HILITE:
  73.             if(!GetColor(center, "\pHilite Color", 
  74.                 &(**(**some_new_colors).awCTable).ctTable[3].rgb, &selected_color))
  75.                     { SysBeep(10); return; }
  76.             (**(**some_new_colors).awCTable).ctTable[3].value = wHiliteColor;
  77.             (**(**some_new_colors).awCTable).ctTable[3].rgb.red = selected_color.red;
  78.             (**(**some_new_colors).awCTable).ctTable[3].rgb.green = selected_color.green;
  79.             (**(**some_new_colors).awCTable).ctTable[3].rgb.blue = selected_color.blue;
  80.             break;
  81.         
  82.         case TITLE:    
  83.             if(!GetColor(center, "\pTitle Bar", 
  84.                 &(**(**some_new_colors).awCTable).ctTable[4].rgb, &selected_color))
  85.                     { SysBeep(10); return; }
  86.             (**(**some_new_colors).awCTable).ctTable[4].value = wTitleBarColor;
  87.             (**(**some_new_colors).awCTable).ctTable[4].rgb.red = selected_color.red;
  88.             (**(**some_new_colors).awCTable).ctTable[4].rgb.green = selected_color.green;
  89.             (**(**some_new_colors).awCTable).ctTable[4].rgb.blue = selected_color.blue;
  90.             break;
  91.         }
  92.     
  93.     SetWinColor(aWindow, (**some_new_colors).awCTable);
  94.     HUnlock((**some_new_colors).awCTable);    /* Now that SetWinColor is done, I'll unlock the handle */
  95.     
  96.     SetPort(savedPort);            /* restore the Graf Port */
  97. }
  98.  
  99. /* 
  100.         Change_control_color will take the indicated control componet from the 
  101.         selected window and the prompt the user for the desired color
  102.         NOTE: If there exists more than one control with the same componet, then 
  103.         change_control_coor will change the componet for all the controls.
  104.         the user will be prompted for the color for each scroll bar 
  105. */ 
  106. change_control_color(control_region, aWindow)    /* this will change a scroll bar's color */
  107. CWindowPtr    aWindow;
  108. short    control_region;
  109. {
  110. Point    center = {0, 0};    /* This will tell "GetColor" to center the dialog window */
  111. RGBColor    selected_color;
  112. AuxCtlHndl    some_new_colors = 0;
  113. Boolean        aux_test;
  114. CWindowPeek    peek;
  115. ControlHandle    control;
  116. CGrafPtr    savedPort;
  117.  
  118.     GetPort(&savedPort);        /* Save the Graf Port */
  119.  
  120. /* I want to call GetAuxCtl to get the window's ColorTable that I created when the window 
  121.     was first defined, then I can change the colors the way the user wants */
  122.  
  123.     peek = (CWindowPeek)aWindow;
  124.     control = peek->controlList;    /* get the first control */
  125.         
  126.  
  127.     while(control)
  128.     {
  129.         aux_test =     GetAuxCtl(control, &some_new_colors);    /* get this window's current color definitions */
  130.         if(!aux_test) /* if there are no Auxillary Control records then lets skip this control! */
  131.             break;    
  132.     
  133.         HLock((**some_new_colors).acCTable);    /* Lock it just in case SetCtlColor or GetColor de-references the Handle */
  134.         
  135.         switch(control_region)    /* depending on which part of the window they want to change the color */
  136.         {
  137.                         
  138.             case cFRAME:
  139.                 if(!GetColor(center, "\pControl Frame", 
  140.                         &(**(**some_new_colors).acCTable).ctTable[0].rgb, &selected_color))
  141.                             { SysBeep(10); break; }
  142.                 (**(**some_new_colors).acCTable).ctTable[0].value = cFrameColor;
  143.                 (**(**some_new_colors).acCTable).ctTable[0].rgb.red = selected_color.red;
  144.                 (**(**some_new_colors).acCTable).ctTable[0].rgb.green = selected_color.green;
  145.                 (**(**some_new_colors).acCTable).ctTable[0].rgb.blue = selected_color.blue;
  146.                 break;
  147.                 
  148.             case cBODY:
  149.                 if(!GetColor(center, "\pControl Body", 
  150.                     &(**(**some_new_colors).acCTable).ctTable[1].rgb, &selected_color))
  151.                         { SysBeep(10); break; }
  152.                 (**(**some_new_colors).acCTable).ctTable[1].value = cBodyColor;
  153.                 (**(**some_new_colors).acCTable).ctTable[1].rgb.red = selected_color.red;
  154.                 (**(**some_new_colors).acCTable).ctTable[1].rgb.green = selected_color.green;
  155.                 (**(**some_new_colors).acCTable).ctTable[1].rgb.blue = selected_color.blue;
  156.                 break;
  157.             
  158.             case cTEXT:    
  159.                 if(!GetColor(center, "\pControl Text", 
  160.                     &(**(**some_new_colors).acCTable).ctTable[2].rgb, &selected_color))
  161.                         { SysBeep(10); break; }
  162.                 (**(**some_new_colors).acCTable).ctTable[2].value = cTextColor;    /* I'm not totally certain what this does for a scroll bar */
  163.                 (**(**some_new_colors).acCTable).ctTable[2].rgb.red = selected_color.red;
  164.                 (**(**some_new_colors).acCTable).ctTable[2].rgb.green = selected_color.green;
  165.                 (**(**some_new_colors).acCTable).ctTable[2].rgb.blue = selected_color.blue;
  166.                 break;
  167.  
  168.             case cTHUMB:    
  169.                 if(!GetColor(center, "\pScroll Thumb", 
  170.                     &(**(**some_new_colors).acCTable).ctTable[3].rgb, &selected_color))
  171.                         { SysBeep(10); break; }
  172.                 (**(**some_new_colors).acCTable).ctTable[3].value = cThumbColor;
  173.                 (**(**some_new_colors).acCTable).ctTable[3].rgb.red = selected_color.red;
  174.                 (**(**some_new_colors).acCTable).ctTable[3].rgb.green = selected_color.green;
  175.                 (**(**some_new_colors).acCTable).ctTable[3].rgb.blue = selected_color.blue;
  176.                 break;
  177.             }
  178.         
  179.         SetCtlColor(control, (**some_new_colors).acCTable);
  180.         HUnlock((**some_new_colors).acCTable);    /* Now that SetCtlColor is done, I'll unlock the handle */
  181.     
  182.         control = (*control)->nextControl;
  183.     }    
  184.     SetPort(savedPort);            /* restore the Graf Port */
  185. }
  186.  
  187.